<!--设置模块唯一ID-->
<div id="aq_kucunbiao">
<!--标题、面包屑-->
<section class="content-header">
    <h1>
        库存表
        <small>奥桥</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
        <li>奥桥</li>
        <li class="active">库存表</li>
    </ol>
</section>
<!--列表-->
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <div class="btn-group pull-left" data-type="actionBar">
                        <button type="button" class="btn btn-default" data-action="ruku_add"><i class="fa fa-plus"></i> 入库</button>
                        <button type="button" class="btn btn-default" data-action="chuku_add"><i class="fa fa-pencil"></i> 出库</button>
                        <button type="button" class="btn btn-default" data-action="caigoushenqing"><i class="fa fa-pencil"></i> 采购申请</button>
                        <button type="button" class="btn btn-default" data-action="baosunshenqing"><i class="fa fa-pencil"></i> 报损申请</button>
                        <button type="button" class="btn btn-default" data-action="shangpintiaobodanshenqing"><i class="fa fa-pencil"></i> 商品调拨单申请</button>
                    </div>
                    <div class=" pull-right" data-type="columnControl">
                    </div>
                    <div class=" pull-right " data-type="searchControl">
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="box-body">
                    <table class="table table-bordered table-striped table-hover" style="width:2500px;"></table>
                </div>
            </div>
        </div>
    </div>
</section>

<script type="text/template" data-for="tp_editor">
    <form role="form" class="form-horizontal">
        <div class="box-body">
            <div class="form-group">
                <label class="col-sm-2 control-label">报损原因</label>
                <div class="col-sm-4">
                    <select class="form-control" name="p1">
                        <option>调增</option>
                        <option>调减</option>
                    </select>
                </div>
                <label class="col-sm-2 control-label">调整数量</label>
                <div class="col-sm-4">
                    <input class="form-control" name="p4" value="<%=data.p4?data.p4:''%>"/>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label">子公司名称</label>

                <div class="col-sm-10">
                    <textarea class="form-control" name="p2">
                         <%=data.p2?data.p2:''%>
                    </textarea>
                </div>
            </div>
        </div>
    </form>
</script>

<script>
    USEN(function () {
        //模块ID(全系统唯一)
        var id = "#aq_kucunbiao";
        var ruku_add = "aq_kucunbiao_ruku_add";
        var chuku_add = "aq_kucunbiao_chuku_add";
        var caigoushenqing = "aq_caigoushenqing";
        var shangpintiaobodanshenqing = "aq_kucunbiao_shangpintiaobodanshenqing";

        //定义页面变量
        var $el = $(id);
        var $actionBar = $el.find("[data-type=actionBar]");
        var tableId = id + " table.table";
        var $table = $(tableId);
        var myTable;
        var $editor = $el.find("[data-for=tp_editor]");


        //定义增\删\改 方法
        var editor = {
            ruku_add: function () {
                USEN.load(USEN.router[ruku_add]);
            },
            chuku_add: function () {
                USEN.load(USEN.router[chuku_add]);
            },
            caigoushenqing: function () {
                USEN.load(USEN.router[caigoushenqing]);
            },
            shangpintiaobodanshenqing: function () {
                USEN.load(USEN.router[shangpintiaobodanshenqing]);
            },
            baosunshenqing: function(){
                USEN.modal({
                    title:"报损申请",
                    submitTxt:"提交",
                    submitCb:function($el){
                        //提交表单
                        $el.find("form").ajaxSubmit({
                            url: './simdata/common_add_action.json',
                            beforeSubmit: function (data) {
                         //      console.log("数据提交之前.")
                            },
                            success: function (data, state, obj) {
                                USEN.notifyAlert({
                                    title:"提示:",
                                    content:'提交成功,刷新Table组件'
                                });
                                $el.modal("hide");
                                if (myTable) myTable.ajax.reload();
                            }
                        })
                    },
                    filter:function(data){
                        return _.template($editor.html())({
                            data:data
                        });
                    }
                });
            }
        };

        // 绑定列表编辑按钮事件
        $actionBar.find("[data-action]").on("click", function () {
            var action = $(this).data("action");
            var $selected = $table.find('tr.selected');
            switch (action) {
                case "ruku_add" :
                    editor.ruku_add();
                    break;
                case "chuku_add" :
                    editor.chuku_add();
                    break;
                case "caigoushenqing" :
                    editor.caigoushenqing();
                    break;
                case "baosunshenqing" :
                    editor.baosunshenqing();
                    break;
                case "shangpintiaobodanshenqing" :
                    editor.shangpintiaobodanshenqing();
                    break;
            }
        });

        //初始化datatable数据列表
        myTable = new USEN.Datatable({
            //设置ID
            "id": tableId,
            //设置列控制模块容器
            "columnControl": id + " [data-type=columnControl]",
            //设置搜索模块容器
            "searchControl": id + " [data-type=searchControl]",
            //配置服务
            "ajax": "./simdata/common_table_ation.json",
            //列设置
            "columns": [
                {
                    data: null,
                    defaultContent: '',
                    className: 'select-checkbox',
                    orderable: false, searchable: false,
                    width: "30px"
                },
                { "title": "编号", "data": "p2"},
                { "title": "商品条形码", "data": "p3"},
                { "title": "类别", "data": "p4" },
                { "title": "名称", "data": "p5" },
                { "title": "颜色", "data": "p6" },
                { "title": "规格", "data": "p7" },
                { "title": "单位", "data": "p7" },
                { "title": "数量", "data": "p7" },
                { "title": "单价", "data": "p7" },
                { "title": "金额", "data": "p7" },
                { "title": "批次", "data": "p7" },
                { "title": "供应商", "data": "p7" },
                { "title": "所属库房", "data": "p7" },
                { "title": "备注", "data": "p7" }
            ]
        })
    });
</script>
</div>